package com.software.levelupandroid.utils;

import android.content.Context;

import com.loper7.date_time_picker.DateTimeConfig;
import com.loper7.date_time_picker.dialog.CardDatePickerDialog;

import java.util.Calendar;

/**
 * @Description TODO
 * @Author LiangYaJie
 * @CreateTime 2024年05月09日 15:29:42
 */
public class DialogUtil {

    // 回调接口，用于处理日期选择后的操作
    public interface OnDateChosenListener{
        void onDateChosen(Long aLong);
    }

    // 静态方法，用于显示CardDatePickerDialog
    public static void showCardDatePickerDialog(Context context, String title, OnDateChosenListener listener){
        Calendar calendar = Calendar.getInstance();

        CardDatePickerDialog cardDatePickerDialog = new CardDatePickerDialog.Builder(context)
                .setTitle(title)
                .showBackNow(false)
                .setOnChoose("确定", aLong -> {
//                    String time = DateUtil.convertDateSecondToString(aLong, pattern);
                    if (listener != null){
                        listener.onDateChosen(aLong);
                    }
                    return null;
                })
                .setBackGroundModel(CardDatePickerDialog.CARD)
                .setDisplayType(DateTimeConfig.YEAR, DateTimeConfig.MONTH, DateTimeConfig.DAY, DateTimeConfig.HOUR, DateTimeConfig.MIN)
                .setDefaultTime(calendar.getTimeInMillis())
                .setLabelText("年", "月", "日", "时", "分", "秒")
                .build();

        cardDatePickerDialog.show();
    }

}
